package com.whc.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.whc.entity.Category;
import com.whc.mapper.CategoryMapper;
import com.whc.service.CategoryService;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 韦红材
 * @ClassName CategoryServiceImpl
 * @data 2024/11/26 22:05
 * @Version V1.0
 **/
@Service
public class CategoryServiceImpl implements CategoryService {
    @Autowired
    private CategoryMapper categoryMapper;
    @Override
    public List<Category> selectAll() {
        return categoryMapper.selectList(null);
    }

    @Override
    public Category selectOne(long id) {
        return categoryMapper.selectById(id);
    }

    @Override
    public void update(Category category) {
        UpdateWrapper<Category> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("id",category.getId());
        categoryMapper.update(category,updateWrapper);
    }

    @Override
    public void delete(long id) {
        categoryMapper.deleteById(id);
    }

    @Override
    public void add(String categoryName) {
        Category category = new Category();
        category.setCategoryName(categoryName);
        categoryMapper.insert(category);
    }
}
